<?php

class NewsObject {

	private $_id;
	private $_date;
	private $_title;
	private $_display;
	private $_text;
	private $_imgsTab = Array();
	
	public function __construct($data) {
		$this->hydrate($data);
		$this->constructImgs();
	}
	
	public function hydrate(array $data) {
		foreach ($data as $key => $value) {
			$method = 'set'.ucfirst($key);
			if (method_exists($this, $method)) {
				$this->$method($value);
			}
		}
	}
	
	public function constructImgs() {
		$files = glob(PATH_DATAS_NEWS.$this->_id.'/*.*');
		$tImgs = Array();
		for ($i=0; $i<count($files); $i++){
			$img = $files[$i];
			$extension = end(explode('.', $img));
			$imgsmall = dirname($img).'/tb/'.basename(str_replace('.'.$extension, '', $img).'-'.THUMB_SMALL.'.'.$extension);
			$imgmedium = dirname($img).'/tb/'.basename(str_replace('.'.$extension, '', $img).'-'.THUMB_MEDIUM.'.'.$extension);
			$sizeArray = Array('small'=>$imgsmall, 'medium'=>$imgmedium, 'original'=>$img);
			$tImgs[] = $sizeArray;
		}
		$this->setImgsTab($tImgs);
	}
	
	public function setImgsTab($tImgs) {
		$this->_imgsTab = $tImgs;
	}
	
	public function imgsTab() {
		return $this->_imgsTab;
	}
	
	public function id() {
		return $this->_id;
	}
	
	public function display() {
		return $this->_display;
	}
	
	public function date() {
		return $this->_date;
	}
	
	public function title() {
		return $this->_title;
	}
	
	public function text() {
		return $this->_text;
	}
	
	public function setId($id) {
		$this->_id = intval($id);
	}
	
	public function setDisplay($display) {
		$this->_display = intval($display);
	}
	
	public function setDate($date) {
		if (is_string($date)) {
			$this->_date = $date;
		}
	}
	
	public function setTitle($title) {
		if (is_string($title)) {
			$this->_title = $title;
		}
	}
	
	public function setText($text) {
		if (is_string($text)) {
			$this->_text = $text;
		}
	}
	
}

?>